package com.ymatou.iapi.dguser.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.common.lang.CipherUtil;
import com.ymatou.iapi.dguser.parameter.CreateUserBackBean;
import com.ymatou.iapi.dguser.parameter.ExistsSellerMobileBean;
import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymatou.iapi.dguser.service.ExistsSellerMobileCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.utils.TestDataManager;
/**
*商家手机号是否已经存在
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_ExistsSellerMobile{
	private static ExistsSellerMobileBean existssellermobileBean;
	private static ExistsSellerMobileCall existssellermobileCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("商家手机号是否已经存在");
	}
	

	@Before
	public void caseUp() {
		existssellermobileBean=new ExistsSellerMobileBean();
		existssellermobileCall=new ExistsSellerMobileCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(existssellermobileCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ExistsSellerMobile_001() {
		Logger.start(true,"商家手机号存在,验证true");
		try {
			UserCreateBean usercreateBean= DGUserCallService.initUsercreateBean();
			usercreateBean.setMobile(TestDataManager.getPhoneNum());
			usercreateBean.setMobileAreaCode("86");
			usercreateBean.setUserType(1);
			DGUserCallService.UserCreateCall(usercreateBean);
//			System.out.println("encode:"+CipherUtil.encryptAES(JUserCallService.EncryptKey, usercreateBean.getMobile()));
			existssellermobileBean.setMobile(usercreateBean.getMobile());
			existssellermobileBean.setMobileAreaCode(usercreateBean.getMobileAreaCode());
			existssellermobileCall.setData(existssellermobileBean);
			existssellermobileCall.callService();			
			Logger.verifyEquals("true", existssellermobileCall.getString("success"), "验证success");
			Logger.verifyEquals("true", existssellermobileCall.getString("exists"), "验证exists");
		} catch (Throwable e) {
			Logger.fail(new Exception(e));
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_ExistsSellerMobile_002() {
		Logger.start(true,"商家手机号重复区号不同,验证false");
		try {
			UserCreateBean usercreateBean= DGUserCallService.initUsercreateBean();
			usercreateBean.setMobile(TestDataManager.getPhoneNum());
			usercreateBean.setMobileAreaCode("86");
			DGUserCallService.UserCreateCall(usercreateBean);
			existssellermobileBean.setMobile(usercreateBean.getMobile());
			existssellermobileBean.setMobileAreaCode(usercreateBean.getMobileAreaCode()+1);
			existssellermobileCall.setData(existssellermobileBean);
			existssellermobileCall.callService();			
			Logger.verifyEquals("true", existssellermobileCall.getString("success"), "验证success");
			Logger.verifyEquals("false", existssellermobileCall.getString("exists"), "验证exists");
			
		}  catch (Throwable e) {
			Logger.fail(new Exception(e));
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_ExistsSellerMobile_003() {
		Logger.start(true,"商家不同手机号,验证false");
		try {
			UserCreateBean usercreateBean= DGUserCallService.initUsercreateBean();
			usercreateBean.setMobile(TestDataManager.getPhoneNum());
			usercreateBean.setMobileAreaCode("86");
			DGUserCallService.UserCreateCall(usercreateBean);
			existssellermobileBean.setMobile(usercreateBean.getMobile()+1);
			existssellermobileBean.setMobileAreaCode(usercreateBean.getMobileAreaCode());
			existssellermobileCall.setData(existssellermobileBean);
			existssellermobileCall.callService();			
			Logger.verifyEquals("true", existssellermobileCall.getString("success"), "验证success");
			Logger.verifyEquals("false", existssellermobileCall.getString("exists"), "验证exists");
			
		}  catch (Throwable e) {
			Logger.fail(new Exception(e));
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_ExistsSellerMobile_004() {
		Logger.start(true,"不输入手机号失败");
		try {
			UserCreateBean usercreateBean= DGUserCallService.initUsercreateBean();
			usercreateBean.setMobile(TestDataManager.getPhoneNum());
			usercreateBean.setMobileAreaCode("86");
			DGUserCallService.UserCreateCall(usercreateBean);
//			existssellermobileBean.setMobile(usercreateBean.getMobile()+1);
			existssellermobileBean.setMobileAreaCode(usercreateBean.getMobileAreaCode());
			existssellermobileCall.setData(existssellermobileBean);
			existssellermobileCall.callService();			
			Logger.verifyEquals("false", existssellermobileCall.getString("success"), "验证success");
			
		}  catch (Throwable e) {
			Logger.fail(new Exception(e));
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_ExistsSellerMobile_005() {
		Logger.start(true,"不输入区号失败");
		try {
			UserCreateBean usercreateBean= DGUserCallService.initUsercreateBean();
			usercreateBean.setMobile(TestDataManager.getPhoneNum());
			usercreateBean.setMobileAreaCode("86");
			DGUserCallService.UserCreateCall(usercreateBean);
			existssellermobileBean.setMobile(usercreateBean.getMobile());
//			existssellermobileBean.setMobileAreaCode(usercreateBean.getMobileAreaCode());
			existssellermobileCall.setData(existssellermobileBean);
			existssellermobileCall.callService();			
			Logger.verifyEquals("false", existssellermobileCall.getString("success"), "验证success");
			
		}  catch (Throwable e) {
			Logger.fail(new Exception(e));
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ExistsSellerMobile_006() {
		Logger.start(true,"商家手机号不存在但是存在相同的买家手机号,验证false");
		try {
			UserCreateBean usercreateBean= DGUserCallService.initUsercreateBean();
			usercreateBean.setMobile(TestDataManager.getPhoneNum());
			usercreateBean.setMobileAreaCode("86");
//			usercreateBean.setUserType(1);
			DGUserCallService.UserCreateCall(usercreateBean);
//			System.out.println("encode:"+CipherUtil.encryptAES(JUserCallService.EncryptKey, usercreateBean.getMobile()));
			existssellermobileBean.setMobile(usercreateBean.getMobile());
			existssellermobileBean.setMobileAreaCode(usercreateBean.getMobileAreaCode());
			existssellermobileCall.setData(existssellermobileBean);
			existssellermobileCall.callService();			
			Logger.verifyEquals("true", existssellermobileCall.getString("success"), "验证success");
			Logger.verifyEquals("false", existssellermobileCall.getString("exists"), "验证exists");
		} catch (Throwable e) {
			Logger.fail(new Exception(e));
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	//和开发确认 戈建华 刘宏 区号统一由刘宏配置不存在歧义 不判断此场景
	public void Tc_ExistsSellerMobile_007() {
		Logger.start(true,"商家手机号存在区号前置0,验证true");
		try {
			UserCreateBean usercreateBean= DGUserCallService.initUsercreateBean();
			usercreateBean.setMobile(TestDataManager.getPhoneNum());
			usercreateBean.setMobileAreaCode("86");
			usercreateBean.setUserType(1);
			DGUserCallService.UserCreateCall(usercreateBean);
//			System.out.println("encode:"+CipherUtil.encryptAES(JUserCallService.EncryptKey, usercreateBean.getMobile()));
			existssellermobileBean.setMobile(usercreateBean.getMobile());
			existssellermobileBean.setMobileAreaCode(0+usercreateBean.getMobileAreaCode());
			existssellermobileCall.setData(existssellermobileBean);
			existssellermobileCall.callService();			
			Logger.verifyEquals("true", existssellermobileCall.getString("success"), "验证success");
			Logger.verifyEquals("true", existssellermobileCall.getString("exists"), "验证exists");
		} catch (Throwable e) {
			Logger.fail(new Exception(e));
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ExistsSellerMobile_008() {
		Logger.start(true,"商家手机号在这个wxapp内存在");
		try {
			CreateUserBackBean usercreateBean= DGUserCallService.initUsercreateNewBean();
			usercreateBean.setUserType(1);
			Integer userid = DGUserCallService.UserCreateNewCall(usercreateBean);
			DGUserCallService.ReceiveUserCreateNewCall(userid);
			existssellermobileBean.setMobile(usercreateBean.getMobile());
			existssellermobileBean.setMobileAreaCode(usercreateBean.getMobileAreaCode());
			existssellermobileBean.setWxAppName(userid+"");
			existssellermobileCall.setData(existssellermobileBean);
			existssellermobileCall.callService();			
			Logger.verifyEquals("true", existssellermobileCall.getString("success"), "验证success");
			Logger.verifyEquals("true", existssellermobileCall.getString("exists"), "验证exists");
		} catch (Throwable e) {
			Logger.fail(new Exception(e));
		}
	}
	 
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ExistsSellerMobile_009() {
		Logger.start(true,"手机号在这个wxapp内存在，不过是用户手机号，不存在");
		try {
			CreateUserBackBean usercreateBean= DGUserCallService.initUsercreateNewBean();
			Integer userid = DGUserCallService.UserCreateNewCall(usercreateBean);
			existssellermobileBean.setMobile(usercreateBean.getMobile());
			existssellermobileBean.setMobileAreaCode(usercreateBean.getMobileAreaCode());
			existssellermobileBean.setWxAppName(userid+"");
			existssellermobileCall.setData(existssellermobileBean);
			existssellermobileCall.callService();			
			Logger.verifyEquals("true", existssellermobileCall.getString("success"), "验证success");
			Logger.verifyEquals("false", existssellermobileCall.getString("exists"), "验证exists");
		} catch (Throwable e) {
			Logger.fail(new Exception(e));
		}
	}
	
	
}